2 * libssl_compat.h -- OpenSSL v1.1 compatibility shims
4 * ---------------------------------------------------------------------
6 * Written by Juergen Perlinger <perlinger@ntp.org> for the NTP project
8 * Based on an idea by Kurt Roeckx <kurt@roeckx.be>
10 * ---------------------------------------------------------------------
11 * This is a clean room implementation of shim functions that have
12 * counterparts in the OpenSSL v1.1 API but not in earlier versions.
14 * If the OpenSSL version used for compilation needs the shims (that is,
15 * does not provide the new functions) the names of these functions are
16 * redirected to our shims.
17 * ---------------------------------------------------------------------
20 #ifndef NTP_LIBSSL_COMPAT_H
21 #define NTP_LIBSSL_COMPAT_H
23 #include "openssl/evp.h"
24 #include "openssl/dsa.h"
25 #include "openssl/rsa.h"
27 /* ----------------------------------------------------------------- */
28 #if OPENSSL_VERSION_NUMBER < 0x10100000L
29 /* ----------------------------------------------------------------- */
31 # include <openssl/objects.h>
32 # include <openssl/x509.h>
34 /* shim the new-style API on an old-style OpenSSL */
36 extern BN_GENCB* sslshimBN_GENCB_new(void);
37 extern void sslshimBN_GENCB_free(BN_GENCB*);
39 extern EVP_MD_CTX* sslshim_EVP_MD_CTX_new(void);
40 extern void sslshim_EVP_MD_CTX_free(EVP_MD_CTX *ctx);
42 extern int sslshim_EVP_PKEY_id(const EVP_PKEY * pkey);
43 extern int sslshim_EVP_PKEY_base_id(const EVP_PKEY * pkey);
44 extern RSA* sslshim_EVP_PKEY_get0_RSA(EVP_PKEY * pkey);
45 extern DSA* sslshim_EVP_PKEY_get0_DSA(EVP_PKEY * pkey);
47 extern void sslshim_RSA_get0_key(const RSA *prsa, const BIGNUM **pn,
48 const BIGNUM **pe, const BIGNUM **pd);
49 extern int sslshim_RSA_set0_key(RSA *prsa, BIGNUM *n,
50 BIGNUM *e, BIGNUM *d);
51 extern void sslshim_RSA_get0_factors(const RSA *prsa, const BIGNUM **pp,
53 extern int sslshim_RSA_set0_factors(RSA *prsar, BIGNUM *p, BIGNUM *q);
54 extern int sslshim_RSA_set0_crt_params(RSA *prsa, BIGNUM *dmp1,
55 BIGNUM *dmq1, BIGNUM *iqmp);
57 extern void sslshim_DSA_SIG_get0(const DSA_SIG *psig, const BIGNUM **pr,
59 extern int sslshim_DSA_SIG_set0(DSA_SIG *psig, BIGNUM *r, BIGNUM *s);
60 extern void sslshim_DSA_get0_pqg(const DSA *pdsa, const BIGNUM **pp,
61 const BIGNUM **pq, const BIGNUM **pg);
62 extern int sslshim_DSA_set0_pqg(DSA *pdsa, BIGNUM *p, BIGNUM *q, BIGNUM *g);
63 extern void sslshim_DSA_get0_key(const DSA *pdsa, const BIGNUM **ppub_key,
64 const BIGNUM **ppriv_key);
65 extern int sslshim_DSA_set0_key(DSA *pdsa, BIGNUM *pub_key,
68 extern int sslshim_X509_get_signature_nid(const X509 *x);
70 #define BN_GENCB_new sslshimBN_GENCB_new
71 #define BN_GENCB_free sslshimBN_GENCB_free
73 #define EVP_MD_CTX_new sslshim_EVP_MD_CTX_new
74 #define EVP_MD_CTX_free sslshim_EVP_MD_CTX_free
76 #define EVP_PKEY_id sslshim_EVP_PKEY_id
77 #define EVP_PKEY_base_id sslshim_EVP_PKEY_base_id
78 #define EVP_PKEY_get0_RSA sslshim_EVP_PKEY_get0_RSA
79 #define EVP_PKEY_get0_DSA sslshim_EVP_PKEY_get0_DSA
81 #define RSA_get0_key sslshim_RSA_get0_key
82 #define RSA_set0_key sslshim_RSA_set0_key
83 #define RSA_get0_factors sslshim_RSA_get0_factors
84 #define RSA_set0_factors sslshim_RSA_set0_factors
85 #define RSA_set0_crt_params sslshim_RSA_set0_crt_params
87 #define DSA_SIG_get0 sslshim_DSA_SIG_get0
88 #define DSA_SIG_set0 sslshim_DSA_SIG_set0
89 #define DSA_get0_pqg sslshim_DSA_get0_pqg
90 #define DSA_set0_pqg sslshim_DSA_set0_pqg
91 #define DSA_get0_key sslshim_DSA_get0_key
92 #define DSA_set0_key sslshim_DSA_set0_key
94 #define X509_get_signature_nid sslshim_X509_get_signature_nid
96 /* ----------------------------------------------------------------- */
97 #endif /* OPENSSL_VERSION_NUMBER < v1.1.0 */
98 /* ----------------------------------------------------------------- */
100 #endif /* NTP_LIBSSL_COMPAT_H */